<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <title>
        <%=global.name%>
    </title>

    <meta name="HandheldFriendly" content="True" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link rel="shortcut icon" href="/favicon.ico" />
    <link rel="stylesheet" type="text/css" href="/css/screen.css" />
    <link rel="canonical" href="https://xiaopinzy.com/" />
    <meta name="referrer" content="origin" />
    <link rel="next" href="https://xiaopinzy.com/page/2/" />

    <script src="/js/jquery.js"></script>
    <script src="/js/jquery.fitvids.min.js"></script>

    <script type="text/javascript" src="js/iscroll.js"></script>

    <link rel="stylesheet" type="text/css" href="/css/xpblog.css" />

    <link rel="stylesheet" href="/css/dropload.css">
    <script src="/js/dropload.min.js"></script>
    <script src="/js/layer/layer.js"></script>

</head>

<body id="wrapper" class="home-template nav-closed">
    <div id="page_content">
        <div id="scroll" class="site-wrapper">
            <%if(user.coverplan != ''){%>
                <header class="main-header no-cover" style="background-image:url('<%=user.coverplan%>')">
                    <%}else{%>
                        <header class="main-header no-cover">
                            <%}%>
                                <nav class="main-nav overlay clearfix">
                                    <a class="blog-logo" href="/"><img src="<%=global.logo%>" alt="<%=global.name%>" /></a>
                                </nav>
                                <div class="vertical">
                                    <div class="main-header-content inner">
                                        <h1 id="artName" class="page-title"><%=user.nickname%></h1>
                                    </div>
                                </div>
                        </header>
                        <section class="content-wrap">
                            <div class="container">
                                <div class="raw" id="bodycontent">
                                    <main id="content" class="main-content1 main-content2" style="width:100%" role="main">
                                        <div id="lists"></div>
                                    </main>
                                </div>
                            </div>
                        </section>
                        <footer class="site-footer clearfix" id="footer">
                            <center>
                                <section class="copyright">
                                    <a href="/">
                                        <%=global.name%>
                                    </a> &copy; 2016
                                </section>
                            </center>
                        </footer>
        </div>
    </div>
    <!-- jQuery1.7以上 或者 Zepto 二选一，不要同时都引用 -->
    <!-- <script src="/js/zepto.min.js"></script> -->
    <script src="/js/dropload.min.js"></script>
    <script>
        var isMobile = {
            Android: function() {
                return navigator.userAgent.match(/Android/i) ? true : false;
            },
            BlackBerry: function() {
                return navigator.userAgent.match(/BlackBerry/i) ? true : false;
            },
            iOS: function() {
                return navigator.userAgent.match(/iPhone|iPad|iPod/i) ? true : false;
            },
            Windows: function() {
                return navigator.userAgent.match(/IEMobile/i) ? true : false;
            },
            any: function() {
                return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Windows());
            }
        };

        Date.prototype.format = function(format) {
            var o = {
                "M+": this.getMonth() + 1, //month
                "d+": this.getDate(), //day
                "h+": this.getHours(), //hour
                "m+": this.getMinutes(), //minute
                "s+": this.getSeconds(), //second
                "q+": Math.floor((this.getMonth() + 3) / 3), //quarter
                "S": this.getMilliseconds() //millisecond
            }
            if (/(y+)/.test(format)) format = format.replace(RegExp.$1,
                (this.getFullYear() + "").substr(4 - RegExp.$1.length));
            for (var k in o)
                if (new RegExp("(" + k + ")").test(format))
                    format = format.replace(RegExp.$1,
                        RegExp.$1.length == 1 ? o[k] :
                        ("00" + o[k]).substr(("" + o[k]).length));
            return format;
        }

        function jsontohtml(art, idprefix) {
            var result = "";

            for (var i = 0; i < art.length; i++) {
                var created = new Date(art[i].created);

                createdstr = created.format("yyyy年MM月dd日");
                createdstr = (createdstr == '1970年01月01日' ? '0000年00月00日' : createdstr);

                var ts = '';
                var tgs = art[i].tags;
                for (var j = 0; j < tgs.length; j++) {
                    if (j == 0) {
                        ts += '标签：';
                    }
                    ts += '<a href="/tags/' + tgs[j] + '">' + tgs[j] + '</a>';
                };
                var text = '<article class="post"><header class="post-header"><h2 class="post-title"><a href="/article/' + art[i]._id + '" id="href_' + idprefix + art[i]._id + '" target="_blank">' + art[i].title + '</a></h2></header><section class="post-excerpt">' + art[i].html.replace(/<[^>]+>/g, "").substr(0, 140) + '......</p></section><footer class="post-meta"><a href="/author/' + art[i].author._id + '">' + art[i].author.nickname + '</a> ' + ts + '<time class="post-date">' + createdstr + '</time></footer></article>';





                result += text;
            }

            return result;
        }

        $(function() {
            function href_click_process(href_id) {
                $("a[id^='" + href_id + "']").click(function() {
                    var _href = $(this).attr("href");
                    var title = $(this).text();

                    $.ajax({
                        type: "GET",
                        url: _href,
                        success: function(data) {
                            layer.open({
                                type: 1,
                                btn: ['关闭'],
                                title: title,
                                content: data,
                                shade: true,
                                style: 'position:fixed; left:0; top:0; width:100%; height:100%; border:none;'
                            });
                        },
                        error: function(data) {

                        }
                    });

                    return false;
                });
            }

            if (isMobile.any()) {
                $('#bodycontent').html(
                    '<main id="content" class="main-content1 main-content2" role="main"><div id="tags"></div><div id="lists"></div></main>'
                );
                $('#footer').html('');
            }

            var pagenum = 0;
            var pagesize = 5;

            // dropload
            $('#content').dropload({
                scrollArea: window,
                domUp: {
                    domClass: 'dropload-up',
                    domRefresh: '<div class="dropload-refresh">↓下拉刷新</div>',
                    domUpdate: '<div class="dropload-update">↑释放更新</div>',
                    domLoad: '<div class="dropload-load"><span class="loading"></span>加载中-请等待...</div>'
                },
                domDown: {
                    domClass: 'dropload-down',
                    domRefresh: '<div class="dropload-refresh">↑上拉加载更多</div>',
                    domLoad: '<div class="dropload-load"><span class="loading"></span>加载中-请等待...</div>',
                    domNoData: '<div class="dropload-noData">已到末页</div>'
                },
                loadUpFn: function(me) {
                    $.ajax({
                        type: "POST",
                        cache: false,
                        url: "/api/article/publishList",
                        data: {
                            pn: 0,
                            ps: pagesize,
                        },
                        success: function(msg) {
                            if (msg.status == 0) {
                                var text = jsontohtml(msg.msg, 0);

                                // 为了测试，延迟1秒加载
                                setTimeout(function() {
                                    $('#lists').append(text);

                                    isMobile.any() && href_click_process("href_0");

                                    // 每次数据加载完，必须重置
                                    me.resetload();

                                    pagenum = 1;

                                    // 解锁
                                    me.unlock();
                                    me.noData(false);
                                }, 250);
                            }
                        },
                        error: function(xhr, type) {
                            // 即使加载出错，也得重置
                            me.resetload();
                        }
                    });
                },
                loadDownFn: function(me) {
                    $.ajax({
                        type: "POST",
                        cache: false,
                        url: "/api/article/authorArtlist",
                        data: {
                            pn: pagenum,
                            ps: pagesize,
                            aid: "<%=id%>"
                        },
                        success: function(msg) {
                            if (msg.status == 0) {
                                var text = jsontohtml(msg.msg, pagenum);

                                // 为了测试，延迟1秒加载
                                setTimeout(function() {
                                    $('#lists').append(text);


                                    isMobile.any() && href_click_process("href_" + pagenum);

                                    if (msg.msg.length < pagesize) {
                                        // 锁定
                                        me.lock();
                                        // 无数据
                                        me.noData();
                                    } else {
                                        pagenum += 1;
                                    }

                                    // 每次数据加载完，必须重置
                                    me.resetload();
                                }, 250);
                            }
                        },
                        error: function(xhr, type) {
                            // 即使加载出错，也得重置
                            me.resetload();
                        }
                    });
                },
                threshold: 50
            });
        });
    </script>

    <script>
        var _hmt = _hmt || [];
        (function() {
            var hm = document.createElement("script");
            hm.src = "//hm.baidu.com/hm.js?c1aa51d40251d7f4363f90cbd95a150b";
            var s = document.getElementsByTagName("script")[0];
            s.parentNode.insertBefore(hm, s);
        })();
    </script>
</body>

</html>